<template>
	<div>
		<el-card
			class="box-card"
			:style="{background:color}"
		>
			<div
				slot="header"
				class="clearfix setFlex"
			>
				<el-tag>{{title}}</el-tag>
				<div class="block">
					<el-tooltip
						class="item"
						effect="dark"
						content="更改背景色"
						placement="top-end"
					>
						<el-color-picker
							v-model="color"
                            size="mini"
							show-alpha
						></el-color-picker>
					</el-tooltip>
				</div>
			</div>
			<div
				id="bar-negative"
				class="chart"
			></div>
		</el-card>
	</div>
</template>

<script>
	export default {
		name: "ZFTXT",
		data() {
			return {
				title: "当前显示：正负条形图组件",
				color: "#FFFFFF",
			};
		},
		mounted() {
			this.$nextTick(() => {
				this.drawLine();
			});
		},
		methods: {
			drawLine() {
				// 基于准备好的dom，初始化echarts实例
				let myChart = this.$echarts.init(document.getElementById("bar-negative"));
				let option = {
					tooltip: {
						trigger: "axis",
						axisPointer: {
							// 坐标轴指示器，坐标轴触发有效
							type: "shadow", // 默认为直线，可选为：'line' | 'shadow'
						},
					},
					legend: {
						data: ["利润", "支出", "收入"],
					},
					grid: {
						left: "3%",
						right: "4%",
						bottom: "3%",
						containLabel: true,
					},
					xAxis: [
						{
							type: "value",
						},
					],
					yAxis: [
						{
							type: "category",
							axisTick: {
								show: false,
							},
							data: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"],
						},
					],
					series: [
						{
							name: "利润",
							type: "bar",
							label: {
								show: true,
								position: "inside",
							},
							emphasis: {
								focus: "series",
							},
							data: [200, 170, 240, 244, 200, 220, 210],
						},
						{
							name: "收入",
							type: "bar",
							stack: "总量",
							label: {
								show: true,
							},
							emphasis: {
								focus: "series",
							},
							data: [320, 302, 341, 374, 390, 450, 420],
						},
						{
							name: "支出",
							type: "bar",
							stack: "总量",
							label: {
								show: true,
								position: "left",
							},
							emphasis: {
								focus: "series",
							},
							data: [-120, -132, -101, -134, -190, -230, -210],
						},
					],
				};
				// 绘制图表
				myChart.setOption(option);
			},
		},
	};
</script>

<style lang="css" scoped>
</style>